
int siftUp(int H[],int i){
    if(i=1)
	return 1;
    while(i!=1){
	if(H[i]>H[i/2]){
	    int tmp=H[i];
	    H[i]=H[i/2];
	    H[i/2]=tmp;
	}
	else
	    return 1;
	i=i/2;
    }
}

int siftDown(int H[],int i){
    if(2*i>H[0])
	return 1;
    while(2*i<=H[0]){
	i=2*i;
	if(i+1<=H[0] && H[i+1]>H[i])
	    i=i+1;
	if(H[i/2]<H[i]){
	    int tmp=H[i];
	    H[i]=H[i/2];
	    H[i/2]=tmp;
	}
	else 
	    return 1;
    }
}

void makeHeap(int A[]){
    for(int i=A[0]/2;i>0;i--){
	siftDown(A,i);
    }
}

int main(int args,char *argv[]){
    int A[]={10,4,3,8,10,11,13,7,30,17,26};
    makeHeap(A);
    for(int i=1;i<=A[0];i++){
	printf("%d\t",A[i]);
    }
}
